package com.greenant.store.bean;

import java.io.Serializable;

import android.text.TextUtils;

import com.avos.avoscloud.AVACL;
import com.avos.avoscloud.AVClassName;
import com.avos.avoscloud.AVFile;
import com.avos.avoscloud.AVRole;
import com.greenant.store.utils.iLog;
import com.hp.hpl.sparta.Text;

@AVClassName(AntAVObject.CLASS_AVGOODSBASE)
public class AntGoodsBase extends AntAVObject implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4261527796839216354L;

	private static final String TAG = "AntGoodsBase";

	public static final String ATTR_DESCRIPTION = "description";
	public static final String ATTR_SPECS = "specs";
	public static final String ATTR_UNIT = "unit";
	// 分类
	public static final String ATTR_STYLE = "style";
	public static final String ATTR_IMAGE_URL = "image";

	// 每次更改增加的量
	public static final String ATTR_WEIGHSTEP = "weighStep";
	// 每次更改增加的量的单位
	public static final String ATTR_WEIGHUNIT = "weighUnit";
	// 是否称重计价
	public static final String ATTR_WEIGHABLE = "weighable";

	private AVRole customRole;
	// 条形码
	public static final String ATTR_GOODCODE = "serialNo";
	// 商品大类
	public static final String ATTR_KIND = "kind";

	public AntGoodsBase() {
		super(AntAVObject.CLASS_AVGOODSBASE);
		setAccessCtrl();
	}

	public AntGoodsBase(String str) {
		super(str);
		setAccessCtrl();
	}

	public String getImageUrl() {
		String url = "";
		try {
			url = this.getAVFile(ATTR_IMAGE_URL).getUrl();
		} catch (Exception e) {
			iLog.e(TAG, "getImageUrl is null");
		}
		if (TextUtils.isEmpty(url)) {
			url = this.getString(ATTR_IMAGE_URL);
		}
		return url;
	}

	public AVFile getImageAVFile() {
		AVFile avFile = null;
		try {
			avFile = this.getAVFile(ATTR_IMAGE_URL);
		} catch (Exception e) {
			iLog.e(TAG, "getImageUrl is null");
		}
		return avFile;
	}

	public String getDescription() {
		return this.getString(ATTR_DESCRIPTION);
	}

	public void setDescription(String descrip) {
		this.put(ATTR_DESCRIPTION, descrip);
	}
	
	public String getSpecsDisStr()
    {
		if(TextUtils.isEmpty(this.getSpecs())) {
			return "";
		}
        return "(" + this.getString(ATTR_SPECS) + ")";
    }
	
	public String getSpecs()
    {
        return this.getString(ATTR_SPECS);
    }

    public void setSpecs(String specs)
    {
        this.put(ATTR_SPECS, specs);
    }
	
	public void setUnit(String descrip) {
		this.put(ATTR_UNIT, descrip);
	}

	public String getUnit() {
		return this.getString(ATTR_UNIT);
	}

	public void setWeighStep(double unit) {
		this.put(ATTR_WEIGHSTEP, unit);
	}

	public double getWeighStep() {
		return this.getDouble(ATTR_WEIGHSTEP);
	}

	public void setWeighUnit(String weighUnit) {
		this.put(ATTR_WEIGHUNIT, weighUnit);
	}

	public String getWeighUnit() {
		if (isWeighAble()) {
			return this.getString(ATTR_WEIGHUNIT);
		} else {
			return getUnit();
		}

	}

	public void setWeighAble(boolean weighAble) {
		this.put(ATTR_WEIGHABLE, weighAble);
	}

	public boolean isWeighAble() {
		return this.getBoolean(ATTR_WEIGHABLE);
	}

	public String getStyle() {
		return this.getString(ATTR_STYLE);
	}

	public void setStyle(String style) {
		this.put(ATTR_STYLE, style);
	}

	public AntGoodsBase getInstance() {
		return this;
	}

	public String getGoodsCode() {
		return this.getString(ATTR_GOODCODE);
	}

	public void setGoodsCode(String userId) {
		this.put(ATTR_GOODCODE, userId);
	}

	public String getKind() {
		return this.getString(ATTR_KIND);
	}

	public void setKind(String userId) {
		this.put(ATTR_KIND, userId);
	}

	private int setAccessCtrl() {

		acl = new AVACL();
		acl.setPublicReadAccess(true);// �˴����õ��������˵Ŀɶ�Ȩ��
		acl.setPublicWriteAccess(false);

		return 0;
	}

}
